using System;
using UnityEngine;

[ExecuteInEditMode]
public class SDFShape : MonoBehaviour
{
    [SerializeField]
    SDFRenderFeature.ShapeData m_ShapeData;

    [SerializeField]
    private Color m_Color = Color.blue;
    [SerializeField]
    private Vector3 m_ScreenPos ;

    public Color Color
    {
        get => m_Color;
        set => m_Color = value;
    }

    private void Awake()
    {
        m_ShapeData.shapeType = 1;
    }

    private void Update()
    {
        m_ShapeData.position =  transform.position;
        m_ShapeData.size =  transform.lossyScale;
        m_ShapeData.color = m_Color;
        
        Vector3 leftUpPoint = transform.position + new Vector3(-transform.localScale.x / 2f, transform.localScale.y / 2f, 0);
        Vector3 rightDownPoint = transform.position + new Vector3(transform.localScale.x / 2f, -transform.localScale.y / 2f, 0);

        m_ScreenPos = Camera.main.WorldToScreenPoint(leftUpPoint);
    }

    private void OnEnable()
    {
        ShapeSDFManager.Instance.AddShape(this);
        Debug.Log("AddShape 1233333333333333");
    }

    private void OnDisable()
    {
        ShapeSDFManager.Instance.RemoveShape(this);
    }

    private void OnDestroy()
    {
    }

    public SDFRenderFeature.ShapeData GetShapeData()
    {
        return m_ShapeData;
    }
}